//抛出store
// applyMiddleware可以使用中间件
import { createStore,applyMiddleware,compose } from 'redux';

//异步跨域请求插件,可以返回一个函数：dispatch只能接受对象，如果传入的是函数则经过该插件会自动先执行这个函数后生成对象传给dispatch
import thunk from 'redux-thunk';

//异步跨域请求插件
import createSageMiddleware from 'redux-saga';
import todoSagas from './sagas';

import reducer from './reducer';

const sagaMiddleware=createSageMiddleware();

//chrome中使用redux调试插件
const composeEnhancers=window.__REDUX_DEVTOOLS_EXTENSION && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__() : compose;
const enchancer = composeEnhancers(
    // applyMiddleware(thunk)
    applyMiddleware(sagaMiddleware)
);

//store表示大型的数据库
//将数据传给数据库
const store = createStore(
    reducer,
    enchancer
);

//运行sagas文件
sagaMiddleware.run(todoSagas);

export default store;